<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.1.min.js"></script>
</head>
<body>
<button id="btn">test</button>
<div id="div1"></div>
<a href="user/loginTest.html">登录</a>
</body>
</html>
<script>
    var examPaper = {
        "name": "JavaEE",
        "clazz": {
            "id": "1"
        },
        "question_list": [
            {
                "order_id": "1",
                "name": "aaa",
                "type": {
                    "id": "1"
                },
                "score": "1.00",
                "option_a": "aaa1",
                "option_b": "bbb1",
                "option_c": "ccc1",
                "option_d": "ddd1",
                "answer": "A"
            },
            {
                "order_id": "2",
                "name": "aaa",
                "type": {
                    "id": "1"
                },
                "score": "1.00",
                "option_a": "aaa2",
                "option_b": "bbb2",
                "option_c": "ccc2",
                "option_d": "ddd2",
                "answer": "A"
            },
            {
                "order_id": "3",
                "name": "aaa",
                "type": {
                    "id": "1"
                },
                "score": "1.00",
                "option_a": "aaa3",
                "option_b": "bbb3",
                "option_c": "ccc3",
                "option_d": "ddd3",
                "answer": "A"
            },
        ]
    };
    var record = {
        "user": {
            "id": "1"
        },
        "paper": {
            "id": "1"
        },
        "record_items": [
            {
                "question": {
                    "id": "1"
                },
                "answer": "C"
            },
            {
                "question": {
                    "id": "2"
                },
                "answer": "D"
            },
            {
                "question": {
                    "id": "3"
                },
                "answer": "C"
            },
            {
                "question": {
                    "id": "4"
                },
                "answer": "A"
            },
            {
                "question": {
                    "id": "5"
                },
                "answer": "C"
            }
        ],
        "start_time": "2023-12-20 13:00:00",
        "end_time": "2023-12-20 15:30:00",
    };
    $("#btn").click(function () {
        $.ajax({
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            // url: 'http://localhost:8080/exam/addExam',
            // url: "/exam/addExam",
            // url: "/record/addRecord",
            url: "/exam/search/1",
            // data: JSON.stringify(examPaper),
            // data: JSON.stringify(record),
            // type: 'POST',
            type: "GET",
            success: function (result, status, xhr) {
                alert(JSON.stringify(result["data"]["question_dto_list"]));
                $.each(result["data"]["question_dto_list"], function (index, value) {
                    // alert(JSON.stringify(value));
                    var d = $("<div></div>");
                    $("#div1").append(d);
                    var sp = $("<span>" + value["name"] + "</span>");
                    d.append(sp);
                    var ul = $("<ul></ul>");
                    d.append(ul);
                    var opa = $("<li>" + value["option_a"] + "</li>");
                    var opb = $("<li>" + value["option_b"] + "</li>");
                    var opc = $("<li>" + value["option_c"] + "</li>");
                    var opd = $("<li>" + value["option_d"] + "</li>");
                    ul.append(opa);
                    ul.append(opb);
                    ul.append(opc);
                    ul.append(opd);
                });
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('Error: ' + textStatus + ' ' + errorThrown);
            }
        });
        // $.post(
        //     "http://localhost:8080/user/register",
        //     {
        //         name: "syxavier",
        //         password: "123456",
        //         loginName: "哈哈哈",
        //         sex: '1'
        //     },
        //     function (data, status) {
        //         $("#div1").html(data);
        //     },
        //     "json"
        // );
    });
</script>
